package com.yxjx.duoxue.datamodel;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.utils.UIHelper;

public class DMCommentLevelAvg implements Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = 6471883904771509266L;
	private String avgTotalLevel = "0.0";
    private String avgLevel1 = "0.0";
    private String avgLevel2 = "0.0";
    private String avgLevel3 = "0.0";
    private String avgLevel4 = "0.0";
    private Integer visitCount = 0;

    public String getAvgTotalLevel() {
        return avgTotalLevel;
    }

    public void setAvgTotalLevel(String avgTotalLevel) {
        this.avgTotalLevel = avgTotalLevel;
    }

    public String getAvgLevel1() {
        return avgLevel1;
    }

    public void setAvgLevel1(String avgLevel1) {
        this.avgLevel1 = avgLevel1;
    }

    public String getAvgLevel2() {
        return avgLevel2;
    }

    public void setAvgLevel2(String avgLevel2) {
        this.avgLevel2 = avgLevel2;
    }

    public String getAvgLevel3() {
        return avgLevel3;
    }

    public void setAvgLevel3(String avgLevel3) {
        this.avgLevel3 = avgLevel3;
    }

    public String getAvgLevel4() {
        return avgLevel4;
    }

    public void setAvgLevel4(String avgLevel4) {
        this.avgLevel4 = avgLevel4;
    }
    
	public Integer getVisitCount() {
		return visitCount;
	}

	public void setVisitCount(Integer visitCount) {
		this.visitCount = visitCount;
	}

    @Override
    public String toString() {
        return "{\"avgTotalLevel\":\"" + avgTotalLevel + "\", \"avgLevel1\":\"" + avgLevel1 + "\", \"avgLevel2\":\"" + avgLevel2 + "\", \"avgLevel3\":\"" + avgLevel3
                + "\", \"avgLevel4\":\"" + avgLevel4 + ", \"visitCount\":\"" + visitCount + "\"}";
    }
    
    /**
     * Parse commentLevelAvg from string.
     * @param str
     * @return
     */
    public static DMCommentLevelAvg from(String str) {
    	DMCommentLevelAvg comment = null;
    	if (UIHelper.isEmpty(str)) {
    		return null;
    	}
    	try {
    		comment = new DMCommentLevelAvg();
			JSONObject jo = new JSONObject(str);
			comment.setAvgLevel1(jo.getString("avgLevel1"));
			comment.setAvgLevel2(jo.getString("avgLevel2"));
			comment.setAvgLevel3(jo.getString("avgLevel3"));
			comment.setAvgLevel4(jo.getString("avgLevel4"));
			comment.setAvgTotalLevel(jo.getString("avgTotalLevel"));
			comment.setVisitCount(jo.getInt("visitCount"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
    	
    	return comment;
	}
}